package com.example.shoppingmallspringboot.controller;

import com.example.shoppingmallspringboot.entity.Comment;
import com.example.shoppingmallspringboot.service.CommentService;
import com.example.shoppingmallspringboot.util.FwResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "CommentController",description = "商品评论控制器")
@RestController
@RequestMapping("/comment")
public class CommentController {
    
    private  CommentService commentService;

    @Autowired
    public CommentController(CommentService commentService) {
        this.commentService = commentService;
    }

    @GetMapping("/goods/{goodsId}")
    @Operation(summary = "获取商品评论",description = "商品id为参数")
    public FwResult getGoodsComment(@PathVariable("goodsId") Integer goodsId){
        return commentService.getGoodsComment(goodsId);
    }

    @PostMapping("/user")
    @Operation(summary = "用户评论商品",description = "订单id,商品id,用户id，评论内容,评分为参数")
    public FwResult getUserComment(@RequestBody List<Comment> commentList){
        return commentService.UserComment(commentList);
    }

    @GetMapping("/user/{userId}")
    @Operation(summary = "获取用户的评论", description = "用户id为参数")
    public FwResult getUserComments(@PathVariable("userId") Integer userId) {
        return commentService.getUserComments(userId);
    }

    @DeleteMapping("/delete/{commentId}")
    @Operation(summary = "删除评论", description = "评论id为参数")
    public FwResult deleteComment(@PathVariable("commentId") Integer commentId) {
        return commentService.deleteComment(commentId);
    }
}
